<?php

class ModelConfig {

    const DATABASE_CONFIG_PATH = '/data/mytvplus/mstat_report_tool/conf/mstat_report_tool_anaylsis_data_db.xml';
    const XML_PATH_OF_BROWSER = '/data/mytvplus/mstat_report_tool/conf/mstat_report_tool_browser.xml';
    const XML_PATH_OF_OS = '/data/mytvplus/mstat_report_tool/conf/mstat_report_tool_os.xml';
    const SEND_MAIL_CONFIG_PATH = '/data/mytvplus/mstat_report_tool/conf/mstat_report_tool_send_mail.xml';
    const REPORT_TOOL_SETTING_FILE = '/data/mytvplus/mstat_report_tool/conf/mstat_report_tool_setting.xml';
    const IS_DEBUG = false;

    //setting.
    //temp of video access log.
    static public function getTableNameOfVideoViewing() {
        return 'video_access_log_temp';
    }
    
    //temp of video bitrate
    static public function getTableNameOfVideoBitrate() {
        return 'video_access_log_temp';
    }
    
    static public function getTableNameOfFpVideoAccess() {
        return 'fp_video_access_temp';
    }

    //hour table of video viewing report.
    static public function getHourTableNameOfVideoViewing() {
        return 'video_viewing_report_by_hour';
    }

    //day table of video viewing report.
    static public function getDayTableNameOfVideoViewing() {
        return 'video_viewing_report_by_day';
    }
    
    //hour table of video bitrate.
    static public function getHourTableNameOfVideoBitrate() {
        return 'video_bitrate_report_by_hour';
    }

    //day table of video bitrate.
    static public function getDayTableNameOfVideoBitrate() {
        return 'video_bitrate_report_by_day';
    }
    
    //hour table of footprint video access.(OS & Browser)
    static public function getHourTableNameOfOSAndBrowser() {
        return 'os_browser_report_by_hour';
    }

    //day table of footprint video access.(OS & Browser)
    static public function getDayTableNameOfOSAndBrowser() {
        return 'os_browser_report_by_day';
    }

    static public function getTableNameOfSendMail() {
        return 'send_email_list';
    }

    static public function getTableNameOfVideoAccess() {
        return 'video_access_log_temp';
    }

    static public function getTablePrefixName($year_month) {
        if (empty($year_month)) $year_month = date('Y_m');
        return 'video_access_log_'.$year_month;
    }
    
    static public function getTableNameOfSubscription() {
        return 'subscription_log';
    }
    
    static public function getTableNameOfFpVideoAccessWsStat() {
        return 'fp_video_access_ws_stat';
    }

    static public function getToday() {
        return date('Y-m-d');
    }

    //define the static variable of temp table name.    
    static public $video_access = 'video_access_log_temp';
    static public $fp_video_access = 'fp_video_access_temp';

    //check the old table name.
    static public $mstat_inline_old_table = 'daily_member_access';
    static public $mstat_inline_new_table = 'member_access_log';

    static public function getSmtpSetting() {
        $config = ConfigReaderFactory::getInstance()->getConfigReader(self::SEND_MAIL_CONFIG_PATH)->getConfig();
        return (array)$config->smtpParms;
    }

    static public function getActionSetting() {
        $config = ConfigReaderFactory::getInstance()->getConfigReader(self::SEND_MAIL_CONFIG_PATH)->getConfig();
        return (array)$config->actions;
    }

    static public $default_bitrate_null = array(
                                            array('bitrate'=>'200','Total'=>0),
                                            array('bitrate'=>'500','Total'=>0),
                                            array('bitrate'=>'1500','Total'=>0),
                                           );
    static public $time_bucket_list = array(
                                            '5'=>array('time_view_1','time_fav_1'),
                                            '10'=>array('time_view_2','time_fav_2'),
                                            '15'=>array('time_view_3','time_fav_3'),
                                            '20'=>array('time_view_4','time_fav_4')
                                        );

    public function getConfigSetting($title) {
        $result = array();
        $config = ConfigReaderFactory::getInstance()->getConfigReader(self::REPORT_TOOL_SETTING_FILE)->getConfig();
        foreach($config as $key=>$value) {
            if ($key!=$title) continue;
            $tmp = array();
            foreach($value as $k=>$v) {
                $data = (array)$v;
                $key_ = $data['@attributes']['value'];
                $val_ = $data[0];
                $tmp[$key_] = $val_;
            }
            $result[$key] = $tmp;
        }
        return $result[$title];
    }


}

?>
